/*
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is
 *
 * java-concurrency-presentation:
 * concurrency presentation tutorial.
 *
 * The Initial Developer of the Original Code is
 * Marco Antonio Villalobos, Jr.
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): None.
 *
 * ***** END LICENSE BLOCK *****
 */

package presentation.concurrency.bad;


/**
 * A thread that is like radiation, because it mutates a mutable object.
 */
public class Radiation extends Thread{

    /** The number of iterations to perform. */
    private int iterations;
    /** The shared data to mutate. */
    private Mutable shared;
    /** The amount to increment the shared data per iteration. */
    private double increment;

    /**
     * Creates an instance of this thread.
     *
     * @param iterations The number of iterations to perform.
     * @param shared The shared data to mutate.
     * @param increment The amount to increment the shared data per iteration.
     */
    public Radiation(int iterations, Mutable shared, double increment) {
        this.iterations = iterations;
        this.shared = shared;
        this.increment = increment;        
    }

    /**
     * The runnable portion of this thread.
     */
    public void run() {
        for (int i=0;i<iterations;i++) {
            shared.incrementBy(increment);
        }
    }
}
